<?php
namespace Lib\Finance;
/**
 * Description of Personal
 *
 * @author chacha
 * @date 2016-6-3
 */
class Personal {
    
    protected $uid = NULL;
    
    public function __construct($uid) {
        $this->uid = $uid;
    }

    //托管冻结数额
    public function getTuoguan() {
        $total = 0;
        $job = M('job_user')->join("INNER JOIN xia_job j ON j.id=xia_job_user.jobid AND j.moneyin=". \App\Common\Constvars::JOB_SALARYSTATUS_DG)->where("uid=".$this->uid)->find();
        if ($job) {
            if ($job['instalment']== \App\Common\Constvars::JOB_DGTYPE_SINGLE) {
                $total = $job['salary'];
            }
            else if($job['instalment']== \App\Common\Constvars::JOB_DGTYPE_SEVRAL){
                $total = M('instal_stage')->where("jobid=".$job['id'])->sum('amount');
            }
        }
        
        return $total;
    }
    
    //获取财务提醒消息
    public function getTips() {
        $tips = M('finance_tip')->where("uid=".$this->uid." and status=1")->select();
        return $tips;
    }
    
    //进行中职位
    public function getDoingjob() {
        $sql = "SELECT j.id,j.instalment,j.name as jname,ju.jointime,j.salary,ju.income,j.moneyin"
                . " FROM xia_job_user ju,xia_job j"
                . " WHERE ju.uid=".$this->uid." and j.id=ju.jobid";
        $job = M()->query($sql);
        if (is_array($job)) {
            if ($job[0]['instalment']==1) {
                return $job[0];
            }
            else if ($job[0]['instalment']==2){
                $sql2 = "SELECT * FROM xia_instal_stage AS xis WHERE jobid=".$job[0]['id'];
                $ins = M()->query($sql2);
                if (is_array($ins)) {
                    $job[0]['ins'] = $ins;
                    return $job[0];
                }
                return NULL;
            }
        }
        return NULL;
    }
    
    //确认雇主已付款
    public function confirmpayed($job){
        $job['moneyin'] = \App\Common\Constvars::JOB_SALARYSTATUS_FIN;
        if (!is_array($job) || !isset($job['instalment'])) {
            return false;
        }
        if ($job['instalment']==\App\Common\Constvars::JOB_DGTYPE_SINGLE) {
            return M('job')->save($job);
        }
        else if ($job['instalment']==\App\Common\Constvars::JOB_DGTYPE_SEVRAL) {
            return M('instal_stage')->save($job);
        }
        return false;
    }
}
